<template>
	<el-container>
		<el-header style="height: auto;">
			<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
		</el-header>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="createDeposit">创建</el-button>
				<el-button type="danger" plain icon="el-icon-delete" :disabled="selection.length==0" @click="batch_del"></el-button>
			</div>
			<div class="right-panel">
				<el-form-item label="关联企业" style="padding-top: 20px;">
					<el-select v-model="search.entId" clearable filterable :remote-method="remoteMethod" style="width: 100%" placeholder="输入公司名称、或统一信用代码、公司编号进行查询选择">
						<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
					</el-select>
				</el-form-item>
				<div class="right-panel-search">
					<el-input v-model="search.keyword" placeholder="项目名称、编号"></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="recordId" @selection-change="selectionChange" stripe remoteSort remoteFilter>
				<el-table-column type="selection" width="50"></el-table-column>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="缴纳企业" prop="entName" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="企业编号" prop="entCodeNo" width="100" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="招标项目" prop="inviteTitle" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="保证金" prop="deposit" width="100">
					<template #default="scope">
						{{scope.row.deposit}}/元
					</template>
				</el-table-column>
				<el-table-column label="收取时间" prop="revTime" width="100"></el-table-column>
				<el-table-column label="当前状态" prop="status" width="100">
					<template #default="scope">
						<el-tag v-if="scope.row.status=='0'" type="success" effect="dark">未退</el-tag>
						<el-tag v-else-if="scope.row.status=='1'" type="primary" effect="dark">已退</el-tag>
						<el-tag v-else type="info" effect="dark">未知</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="退回时间" prop="backTime" width="200"></el-table-column>
				<el-table-column label="创建时间" prop="createTime" width="150"></el-table-column>
				<el-table-column label="备注说明" prop="remark" width="150" :show-overflow-tooltip="true"></el-table-column>
				<el-table-column label="操作" fixed="right" align="right" width="210">
					<template #default="scope">
						<el-button-group>
							<el-button text type="primary" size="small" @click="table_show(scope.row, scope.$index)">查看</el-button>
							<el-button text type="primary" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
							<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
								<template #reference>
									<el-button text type="primary" size="small">删除</el-button>
								</template>
							</el-popconfirm>
						</el-button-group>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
	<save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></save-dialog>
	<recordDetails v-if="dialog.detailsSave" ref="detailsDialog" @closed="dialog.detailsSave=false"></recordDetails>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter/index.vue'
import recordDetails from './details.vue'
import saveDialog from './save.vue'
export default {
	name: 'Invite File Manage',
	components: {
		saveDialog,
		scSelectFilter,
		recordDetails
	},
	data() {
		return {
			dialog: {
				save: false,
				detailsSave:false
			},
			filterData: [
				{
					title: "日期范围",
					key: "date",
					multiple: false,
					options: [
						{
							label: "全部",
							value: ""
						},
						{
							label: "今日",
							value: "1"
						},
						{
							label: "昨日",
							value: "2"
						},
						{
							label: "一周内",
							value: "3"
						},
						{
							label: "一月内",
							value: "4"
						},
						{
							label: "一月前",
							value: "5"
						}
					]
				},
				{
					title: "是否退回",
					key: "status",
					multiple: false,
					options: [{
						value: '',
						label: '全部'
					},{
						value: '0',
						label: '未退'
					},{
						value: '1',
						label: '已退'
					}],
				}
			],
			apiObj: this.$API.invite.inviteDeposit.getInviteDepositList,
			selection: [],
			options:[],
			search: {
				entId:'',
				status:'',
				keyword: null
			}
		}
	},
	mounted() {
		this.remoteMethod("");
	},
	methods: {
		async remoteMethod(query){
			let res = await this.$API.invite.inviteEnt.getInviteEntListForSelect.get({keyword:query});
			if (res.code == 200) {
				this.options = res.data
			}
		},
		//添加
		createDeposit() {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open()
			})
		},
		//编辑
		table_edit(row) {
			this.dialog.save = true
			this.$nextTick(() => {
				this.$refs.saveDialog.open('edit').setData(row)
			})
		},
		//查看
		table_show(row) {
			this.dialog.detailsSave = true
			this.$nextTick(() => {
				this.$refs.detailsDialog.open("setting").setData(row)
			})
		},
		//删除
		async table_del(row) {
			var res = await this.$API.invite.inviteDeposit.deleteInviteDeposit.post({recordId: row.recordId});
			if (res.code == 200) {
				this.$refs.table.refresh()
				this.$message.success("删除成功")
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//批量删除
		async batch_del() {
			await this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？`, '提示', {
				type: 'warning'
			}).then(async() => {
				var recordIdArr = [];
				for (var i = 0; i < this.selection.length; i++) {
					recordIdArr.push(this.selection[i].recordId);
				}
				const loading = this.$loading();
				var res = await this.$API.invite.inviteDeposit.deleteInviteDepositByIds.post({ids: recordIdArr});
				if (res.code == 200) {
					this.$refs.table.refresh()
					this.$message.success(res.message)
				} else {
					this.$alert(res.message, "提示", {type: 'error'})
				}
				loading.close();
			}).catch(() => {

			})
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		async upsearch() {
			this.$refs.table.upData(this.search)
		},
		filterChange(data){
			this.search.fileType = data.fileType;
			this.search.status = data.status;
			this.$refs.table.upData(this.search)
		},
		//本地更新数据
		handleSaveSuccess() {
			this.$refs.table.refresh()
		}
	}
}
</script>

<style>
</style>
